﻿Imports System.Text
Imports System.Diagnostics.FileVersionInfo
Imports System.IO
Imports Global_Visas_Business_Layer.TasksEvents
Imports System.Windows
Public Class IT
    Public Enum IncidentPriority
        VeryHigh = 1
        High = 2
        Medium = 3
        Low = 4
    End Enum

    Public Shared Function CreateNewIncident(ByVal conid As Long, ByVal conname As String, ByVal Subject As String, ByVal Description As String, ByVal InternalNotes As String, ByVal Priority As IncidentPriority)
        Dim SQL As StringBuilder
        Dim cmn As New CommonFuncs
        Dim incidentno As Long
        Dim emailaddressTo As String
        Dim Msg As StringBuilder
        Try
            SQL = New StringBuilder
            With SQL
                .Append("Insert into d_incident(Incident_RaisedbyID,Incident_RaisedByName,Incident_Subject,Incident_Description,Incident_InternalNotes,Incident_Priority) ")
                .Append("Values(")
                .Append(conid & ",")
                .Append("'" & cmn.SwapQuotes(conname) & "',")
                .Append("'" & cmn.SwapQuotes(Subject) & "',")
                .Append("'" & cmn.SwapQuotes(Description) & "',")
                .Append("'" & cmn.SwapQuotes(InternalNotes) & "',")
                .Append("'" & cmn.SwapQuotes(Priority) & "')")
            End With
            incidentno = CommonDataFunctions.ExecuteSQL(SQL.ToString, True)
            If incidentno > 0 Then
                'Send email to consultant
                emailaddressTo = CommonDataFunctions.GetConEmailFromID(conid)
                Msg = New StringBuilder
                With Msg
                    .Append("The incident has been created successfully and sent to IT.").AppendLine()
                    .Append("Please quote the reference number (" & incidentno & ")" & " to IT for future correspondences regarding this problem.").AppendLine()
                    .Append("-------------------------------------------------").AppendLine()
                    .Append(Description).AppendLine()
                    .Append("-------------------------------------------------").AppendLine()
                    .Append("").AppendLine()
                    .Append(vbCrLf)
                    .Append("Approximate Timelines for issue reloving incidents based on priority").AppendLine()
                    .Append("Very High :   1 day ").AppendLine()
                    .Append("High :   2 days").AppendLine()
                    .Append("Medium :   5 days").AppendLine()
                    .Append("Low :   14 days").AppendLine()

                End With
                If Letters.GblFunc_Send_MailEngine(emailaddressTo, "no-reply@globalvisas.com", "Incident Ref No : " & incidentno & "  Subject: " & Subject, Msg.ToString) > 0 Then
                    Return incidentno
                Else
                    Return 0
                End If
            Else

                Return 0
            End If
        Catch ex As Exception
            Return 0
        Finally
            SQL = Nothing
            cmn = Nothing
            Msg = Nothing
        End Try

    End Function
End Class

